<?php
namespace modules\game\services\method;

use modules\game\services\Rule;

abstract class IMethod{
	private static $_method = [];
	public static $_forceMethod = '';

	protected $_testPoker    = [];//待检验牌
	protected $_testNum      = 0;
	/**
	 * 检测牌规则是否正确
	 * @param  array $poker 牌
	 * @return bool
	 */
	abstract public function test(Array $testPoker);//检测牌
	/**
	 * 出牌策略
	 * @param  array $userPoker 用户当前的牌,已模块
	 * [
	 * 	 1 => [11,13],
	 * 	 2 => [21],
	 * 	 5 => [53],
	 * 	 13 => [131,132,133],
	 * ]
	 * @return array 出的牌 | bool 没有此类型的牌，不出
	 * [
	 * 		21,
	 * ]
	 */
	abstract public function out($userPoker);//出牌 尽量平稳

	/**
	 * 压牌策略
	 * @param  array $userPoker     我目前的牌
	 * @param  array $opponentPoker 当前需要被压的牌
	 * @param  bool  $intense  是否尽力压牌  true是  or false 否
	 * @return array  出牌 | bool: false 压不住
	 */
	abstract public function suppress($userPoker,$opponentPoker,$intense);//压牌 尽量平稳

	/**
	 * 强制出牌策略
	 * 场景 :两人斗地主，激进压牌
	 * 首先 先以炸 为主
	 * 
	 */
	public function forceSuppress($userPoker,$opponentPoker){
		if(count($opponentPoker) === 2) return false;//说明是王炸
		if($userFour = self::getInstance(FourP::$_name)->suppress($userPoker,$opponentPoker,false)){
			self::$_forceMethod = Rule::FOUR_P;
			return $userFour;
		}
		if($userKing = self::getInstance(TwoKing::$_name)->suppress($userPoker,$opponentPoker,false)){
			self::$_forceMethod = Rule::TWO_KING;
			return $userKing;
		}
		return false;
	}
	/**
	 * 单例对象
	 */
	public static function getInstance($methodName = null){
		$methodName = empty($methodName) ? Static::$_name : $methodName;
		if(isset(self::$_method[$methodName])){
			return self::$_method[$methodName];
		}
		return self::$_method[$methodName] = new $methodName;
	}
}